import zlib

file = '1_zlib_压缩数据.py'
# 1.压缩文件
compressor = zlib.compressobj()
with open(file, 'rb') as f:
    with open(f'{file}.zip', 'wb') as f_out:
        while True:
            data = f.read(4096)
            if not data:
                break
            f_out.write(compressor.compress(data))
        f_out.write(compressor.flush())

# 2.从压缩文件中解压
decompressor = zlib.decompressobj()
with open(f'{file}.zip', 'rb') as f:
    with open(f'{file}.out', 'wb') as f_out:
        while True:
            data = f.read(4096)
            if not data:
                break
            f_out.write(decompressor.decompress(data))
            
""" 
1.
压缩文件: 1_zlib_压缩数据.py.zip
unzip , gzip 都无法识别, 无法解压


2.文件大小
317     1_zlib_压缩数据.py
317     1_zlib_压缩数据.py.out
171     1_zlib_压缩数据.py.zip

"""